<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>内部账号管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" th:href="@{/layuiadmin/layui/css/layui.css}" media="all">
  <link rel="stylesheet" th:href="@{/layuiadmin/style/admin.css}" media="all">
</head>
<body>

<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a><cite>管理中心</cite></a>
    <a><cite>内部账号管理</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-card-header card-title">内部账号管理</div>
        <div class="layui-card-body">
          <table class="layui-hide" id="test-table-cellEdit" lay-filter="test-table-cellEdit"></table>
          <script type="text/html" id="test-table-operate-barDemo">
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
          </script>
        </div>
      </div>
    </div>
  </div>
</div>

<script th:src="@{/layuiadmin/layui/layui.js}"></script>
<script th:inline="none">
  layui.config({
    base: '/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table'], function(){
    var table = layui.table;
    var loading = layer.load();
    table.render({
      elem: '#test-table-cellEdit'
      ,url: "/selectnbzhgl"
      ,height: 'full-150'
      ,cols: [[
        {field:'id', title:'人员微信编号', width:180, sort: true}
        ,{field:'openid', title:'微信标识', width:300, sort: true}
        ,{field:'realname', title:'部门-姓名',width:260,edit: 'text',sort:true}
        ,{field:'zcsj', title:'注册时间', width: 300,sort:true}
        ,{title:'操作',width:80, align:'center', toolbar: '#test-table-operate-barDemo'}
      ]]
      ,done:function () {
        layer.close(loading);
      }
    })

    //监听单元格编辑
    table.on('edit(test-table-cellEdit)', function(obj){
      var value = obj.value //得到修改后的值
              ,data = obj.data //得到所在行所有键值
              ,field = obj.field; //得到字段
      $.ajax({
        url:"/aupuser",
        data:{id:data.id,field:field,updateValue:value},
        type:"post",
        dataType:"json",
        success: function (result) {
            if(result)
                layer.msg('修改成功！',{icon:1});
            else
                layer.msg('修改失败',{icon:2});
        },
        error:function (e) {
          layer.msg('修改失败',{icon:2});
        }
      })
    });

    //监听工具条
    table.on('tool(test-table-cellEdit)', function(obj){
      var data = obj.data;
      if(obj.event === 'del'){
        layer.confirm('真的删除行'+data.id+'么', function(index){
          $.ajax({
            url:"/delUser",
            data:{id:data.id},
            type:"post",
            dataType:"json",
            success: function (result) {
                if (result) {
                    layer.msg('[ID: ' + data.id + '] 已删除', {icon: 1});
                    obj.del();
                }
                else
                    layer.msg('删除失败',{icon:2});
            },
            error:function (e) {
              layer.msg('删除失败',{icon:2});
            }
          })
          layer.close(index);
        });
      }
    });
    var $ = layui.$;
  });

</script>
</body>
</html>